local huibian = fk.CreateSkill {
  name = "lvshi__huibian",
  tags = {Skill.Lord, "Phase"},
}

Fk:loadTranslationTable {
  ["lvshi__huibian"] = "挥鞭",
  [":lvshi__huibian"] = "主公技，阶段技，你可选择两名魏势力角色，你对前者造成1点伤害，然后其选择摸两张牌或令后者回复1点体力。",
  ["#lvshi__huibian-prompt"] = "挥鞭：选择两名魏势力角色",

  ["huibian_tip_1"] = "受到伤害",
  ["huibian_tip_2"] = "回复体力",

  ["huibian_draw"] = "摸两张牌",
  ["huibian_recover"] = "令%src回复1点体力",

  ["$lvshi__huibian1"] = "吾任天下之智力，以道御之，无所不可。",
  ["$lvshi__huibian2"] = "青青子衿，悠悠我心，但为君故，沉吟至今。",

}


huibian:addEffect("active", {
  anim_type = "control",
  target_num = 2,
  card_num = 0,
  prompt = "#lvshi__huibian-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(huibian.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
    if #selected < 2 then
      return to_select.kingdom == "wei"
    end
  end,
  target_tip = function(self, player, to_select, selected, _, _, selectable, _)
    if not selectable then return end
    if #selected == 0 or (#selected > 0 and selected[1] == to_select) then
      return "huibian_tip_1"
    else
      return "huibian_tip_2"
    end
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target1 = effect.tos[1]
    local target2 = effect.tos[2]
    room:damage {
      from = player,
      to = target1,
      damage = 1,
      skillName = huibian.name,
    }
    local all_choices = {"huibian_draw", "huibian_recover:"..target2.id}
    local choices = table.simpleClone(all_choices)
    if target1.dead then table.removeOne(choices, "huibian_draw") end
    if target2.dead or not target2:isWounded() then table.removeOne(choices, all_choices[2]) end
    if #choices == 0 then return end
    local choice = room:askToChoice(target1, {
      choices = choices,
      skill_name = huibian.name,
      all_choices = all_choices,
      cancelable = false,
    })
    if choice == "huibian_draw" then
      target1:drawCards(2, huibian.name)
    elseif choice == all_choices[2] then
      room:recover {
        who = target2,
        num = 1,
        recoverBy = player,
        skillName = huibian.name
      }
    end
  end,
})

return huibian
